package com.jiazhong.basic.pack0316.thread.work02;

import java.util.concurrent.locks.Lock;

public class Well {

    private Lock lock;

    public Well(Lock lock) {
        this.lock = lock;
    }

    public void fetchWater() {
        lock.lock();
        String name = Thread.currentThread().getName();
        System.out.print(name + "正在打水");
        for (int i = 0; i < 10; i++) {
            System.out.print(".");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        System.out.println("\n" + name + "打水完毕");
        lock.unlock();
    }
}
